import axios from 'axios'
import qs from 'qs'
export default {
    //get请求
    get(url, param) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'get',
                url,
                params: param,
            }).then(res => { //axios返回的是一个promise对象
                resolve(res) //resolve在promise执行器内部 
            }).catch(err => {
                console.log(err, '异常')
            })

        })
    },
    //post请求
    post(url, param) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'post',
                url,
                data: qs.stringify(param),
            }).then(res => {
                resolve(res)
            }).catch(err => {
                console.log(err, '异常')
            })
        })
    },
    //push请求
    push(url, param) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'push',
                url,
                data: param,
            }).then(res => {
                resolve(res)
            }).catch(err => {
                console.log(err, '异常')
            })
        })
    },
    //delete请求
    delete(url, param) {
        return new Promise((resolve, reject) => {
            axios({
                method: 'delete',
                url,
                data: param,
            }).then(res => {
                resolve(res)
            }).catch(err => {
                console.log(err, '异常')
            })
        })
    }
}